| Conditions | 19 | 
| Total Lines | 54 | 
| Code Lines | 40 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like helper.ts ➔ sortRankings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import { RankingDataTeamObject } from "../Types/Ranking" | 
            ||
| 13 | |||
| 14 | export function sortRankings(a: RankingDataTeamObject, b: RankingDataTeamObject) { | 
            ||
| 15 | // Rank lager: A stijgt in sortering.  | 
            ||
| 16 |   if (a.rank < b.rank) { | 
            ||
| 17 | return -1  | 
            ||
| 18 | }  | 
            ||
| 19 |   if (a.rank > b.rank) { | 
            ||
| 20 | return 1  | 
            ||
| 21 | }  | 
            ||
| 22 | // Aantal overwinningen hoger: A stijgt in sortering.  | 
            ||
| 23 |   if (a.wins > b.wins) { | 
            ||
| 24 | return -1  | 
            ||
| 25 | }  | 
            ||
| 26 |   if (a.wins < b.wins) { | 
            ||
| 27 | return 1  | 
            ||
| 28 | }  | 
            ||
| 29 | // Doelpuntensaldo beter: A stijgt in sortering.  | 
            ||
| 30 |   if (a.goalsScored - a.goalsConceded > b.goalsScored - b.goalsConceded) { | 
            ||
| 31 | return -1  | 
            ||
| 32 | }  | 
            ||
| 33 |   if (a.goalsScored - a.goalsConceded < b.goalsScored - b.goalsConceded) { | 
            ||
| 34 | return 1  | 
            ||
| 35 | }  | 
            ||
| 36 | // Aantal gemaakte doelpunten hoger: A stijgt in sortering.  | 
            ||
| 37 |   if (a.goalsScored > b.goalsScored) { | 
            ||
| 38 | return -1  | 
            ||
| 39 | }  | 
            ||
| 40 |   if (a.goalsScored < b.goalsScored) { | 
            ||
| 41 | return 1  | 
            ||
| 42 | }  | 
            ||
| 43 | // Aantal uitoverwinningen hoger: A stijgt in sortering.  | 
            ||
| 44 |   if (a.winsAway > b.winsAway) { | 
            ||
| 45 | return -1  | 
            ||
| 46 | }  | 
            ||
| 47 |   if (a.winsAway < b.winsAway) { | 
            ||
| 48 | return 1  | 
            ||
| 49 | }  | 
            ||
| 50 | // Doelpuntensaldo op verplaatsing beter: A stijgt in sortering.  | 
            ||
| 51 |   if (a.goalsScoredAway - a.goalsConcededAway > b.goalsScoredAway - b.goalsConcededAway) { | 
            ||
| 52 | return -1  | 
            ||
| 53 | }  | 
            ||
| 54 |   if (a.goalsScoredAway - a.goalsConcededAway < b.goalsScoredAway - b.goalsConcededAway) { | 
            ||
| 55 | return 1  | 
            ||
| 56 | }  | 
            ||
| 57 | // Aantal gemaakte doelpunten op verplaatsing hoger: A stijgt in sortering.  | 
            ||
| 58 |   if (a.goalsScoredAway > b.goalsScoredAway) { | 
            ||
| 59 | return -1  | 
            ||
| 60 | }  | 
            ||
| 61 |   if (a.goalsScoredAway < b.goalsScoredAway) { | 
            ||
| 62 | return 1  | 
            ||
| 63 | }  | 
            ||
| 64 | |||
| 65 | return a.team?.club?.localName.localeCompare(b.team?.club?.localName)  | 
            ||
| 66 | }  | 
            ||
| 67 |